/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.bingoogolapple.badgeview;

import ohos.agp.components.Component;
import ohos.agp.render.Canvas;

import java.util.List;

/**
 * 自定义控件统一添加 canvas
 *
 * @since 2021-04-21
 */
public final class BgaBadgeTool {
    private BgaBadgeTool() {
    }

    /**
     * 注册控件添加canvas
     *
     * @param stackComponent 当前操作的Component
     * @param componentList 所有要添加消息徽章的自定义的Component
     */
    public static void initBgaBadgeDrawView(Component stackComponent, List<BGABadgeable> componentList) {
        stackComponent.addDrawTask(new Component.DrawTask() {
            @Override
            public void onDraw(Component component, Canvas canvas) {
                for (BGABadgeable drawComponent : componentList) {
                    drawComponent.setComponent(stackComponent);
                    drawComponent.setDrawTask(canvas);
                }
            }
        });
    }
}
